﻿using Artech.WcfServices.Contracts;

namespace Artech.WcfServices.Services
{
    using Entity;
    using System.Linq;
    public class UserService : IUser
    {
        static Entity.Car_RentalDataContext db;
        static UserService()
        {
            db = new Entity.Car_RentalDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["Car_Rental"].ToString());
        }
        #region IUser 成员

        public bool Register(Entity.UserBases entity)
        {
            try
            {
                db.UserBases.InsertOnSubmit(entity);
                db.SubmitChanges();
                return true;
            }
            catch (System.Exception)
            {
                return false;
                throw;
            }

        }

        public byte[] GetUserByID(int userID)
        {
            return VCommons.SerializationHelper.ObjectToByteArray(db.GetTable<UserBases>().Select(i => new UserBases_Ext
            {
                UserID = i.UserID,
                Name = i.Name,
            }).FirstOrDefault(i => i.UserID == userID));
        }
        public UserBases GetUserBaseByID(int userID)
        {
            return db.GetTable<UserBases>().FirstOrDefault(i => i.UserID == userID);
        }
        #endregion
    }

}